package com.ruijixiang.leetcode.everyday.leetcode2024.leetcode202409;

public class leetcode20240924 {
    public long maximumSubsequenceCount(String text, String pattern) {
        int count1=0,count2=0;
        long ans=0;
        for(int i=0;i<text.length();i++){
            if(text.charAt(i)==pattern.charAt(0)){
                count1++;
            }else if(text.charAt(i)==pattern.charAt(1)){
                ans+=count1;
                count2++;
            }
        }
        if(pattern.charAt(0)==pattern.charAt(1)){
            return (long)(count1+1)*count1/2;
        }
        return ans+Math.max(count1,count2);
    }
}
